package model.components.nodes.factory;

import model.components.nodes.node.PhysicalNode;
import model.components.nodes.node.PhysicalRouter;
import model.components.nodes.node.PhysicalServer;
import model.components.nodes.node.PhysicalSwitch;

public class PhysicalNodesFactory extends NodesFactory
{	
	public static final int ROUTERS_PERCENTAGE = 10;
	public static final int SWITCHES_PERCENTAGE = 20;
	public static final int SERVERS_PERCENTAGE = 70;
	
	public static final int LINUX_PERCENTAGE = 100;
	public static final int WINDOWS_PERCENTAGE = 0;
	public static final int SOLARIS_PERCENTAGE = 0;
	public static final int ANDROID_PERCENTAGE = 0;
	
	public static final int VMWARE_PERCENTAGE = 100;
	public static final int XEN_PERCENTAGE = 0;
	public static final int KVM_PERCENTAGE = 0;
	public static final int UML_PERCENTAGE = 0;
	
	public static final int MIN_CPU =  50;
	public static final int MAX_CPU = 100;
	
	public static final int MIN_MEMORY =  50;
	public static final int MAX_MEMORY = 100;
	
	public static final int MIN_DISK_SPACE =  50;
	public static final int MAX_DISK_SPACE = 100;
	
	public static final int MAX_VIRTUAL_NODES_NUMBER  = 10;
	
	private int maxVirtualNodesNumber;
	public int getMaxVirtualNodesNumber(){ return maxVirtualNodesNumber; }
	public void setMaxVirtualNodesNumber( int maxVirtualNodesNumber ){ this.maxVirtualNodesNumber = maxVirtualNodesNumber; }

	public PhysicalNodesFactory( String networkName )
	{
		super( networkName, ROUTERS_PERCENTAGE, SWITCHES_PERCENTAGE, SERVERS_PERCENTAGE, LINUX_PERCENTAGE, WINDOWS_PERCENTAGE, SOLARIS_PERCENTAGE, ANDROID_PERCENTAGE, VMWARE_PERCENTAGE, XEN_PERCENTAGE, KVM_PERCENTAGE, UML_PERCENTAGE, MIN_CPU, MAX_CPU, MIN_MEMORY, MAX_MEMORY, MIN_DISK_SPACE, MAX_DISK_SPACE );
		
		this.setMaxVirtualNodesNumber( MAX_VIRTUAL_NODES_NUMBER );
	}

	public PhysicalNodesFactory( String networkName, int routersPercentage, int switchesPercentage, int serversPercentage, int linuxPercentage, int windowsPercentage, int solarisPercentage, int androidPercentage, int vmWarePercentage, int xenPercentage, int kvmPercentage, int umlPercentage, int minCpu, int maxCpu, int minMemory, int maxMemory, int minDiskSpace, int maxDiskSpace, int maxAvailableVirtualNodesNumber )
	{
		super( networkName, routersPercentage, switchesPercentage, serversPercentage, linuxPercentage, windowsPercentage, solarisPercentage, androidPercentage, vmWarePercentage, xenPercentage, kvmPercentage, umlPercentage, minCpu, maxCpu, minMemory, maxMemory, minDiskSpace, maxDiskSpace );
		
		this.setMaxVirtualNodesNumber( maxAvailableVirtualNodesNumber );
	}
	
	@Override
	public PhysicalNode create()
	{
		PhysicalNode physicalNode = null;
		int randomNodeTypePercentage = (int) (100 * Math.random());
		
		if( 0 <= randomNodeTypePercentage && randomNodeTypePercentage < this.getRoutersPercentage() )
			physicalNode = new PhysicalRouter( this.getNetworkName(), this.getNodeCount(), this.randomOperatingSystem(), this.randomVirtualEnvironment(), this.randomCpu(), this.randomMemory(), this.getMaxVirtualNodesNumber() );
		
		else if( this.getRoutersPercentage() <= randomNodeTypePercentage && randomNodeTypePercentage < this.getRoutersPercentage() + this.getSwitchesPercentage() )
			physicalNode = new PhysicalSwitch( this.getNetworkName(), this.getNodeCount(), this.randomOperatingSystem(), this.randomVirtualEnvironment(), this.randomCpu(), this.randomMemory(), this.getMaxVirtualNodesNumber() );
		
		else if( this.getRoutersPercentage() + this.getSwitchesPercentage() <= randomNodeTypePercentage && randomNodeTypePercentage < 100 )
			physicalNode = new PhysicalServer( this.getNetworkName(), this.getNodeCount(), this.randomOperatingSystem(), this.randomVirtualEnvironment(), this.randomCpu(), this.randomMemory(), this.randomDiskSpace(), this.getMaxVirtualNodesNumber() );
		
		if( physicalNode != null )
			this.setNodeCount( this.getNodeCount() + 1 );
		
		return physicalNode;
	}
	
}
